
import { scrollMixin } from "utils/mixin";
var currentTabIndex = "0";
//标记 防止重复加载
var is_first_content = false;
var is_second_content = false;
let activeName = 'first';
let activeName1 = "0";
export default {
  mixins:[scrollMixin],
  data() {
    return {

      mailLanguage:"",
      mailSingleReturnTitle:"",
      mailSingleReturnName:"",
      mailReturnQueue:"",
      mailReturnLog:"",


      // mail_distrbution_name:"",
      // mail_commission:"",



      activeName: "first",
      activeName1:"0",
      first_content: [],
      second_content: [],
      isLoadMore:false,
      alreadyReturn: 0.00,
      each_return_rate: 0,
      order_return_rate: 0,
      returnAmountTotal: 0.00,
      notReturn: 0.00,
      totay:0.00,
      valid:0.00,
      task:false,
      httpUrl:"plugin.single-return.api.single-return.get-single-return-queue",
      logPage:1,
      listData:[],
      noMore:false,
      single_return_show:true
    };
  },

  mounted() {

  },

  activated() {
    this.initMailLanguage();
    this.initData();//初始化参数
    this.getData();//初始化数据
    // this.setDataByTabIndex();
    this.getListData();
  },

  methods: {

    initMailLanguage(){
      this.mailLanguage =this.fun.initMailLanguage();
      console.log(this.mailLanguage,'111111111');
      this.fun.setWXTitle(this.fun.setMailLanguage("消费赠送",this.mailLanguage.single_return?this.mailLanguage.single_return.single_return:''));
      this.mailSingleReturnTitle=this.fun.setMailLanguage("消费赠送",this.mailLanguage.single_return?this.mailLanguage.single_return.single_return:'');
      this.mailSingleReturnName=this.fun.setMailLanguage("赠送",this.mailLanguage.single_return?this.mailLanguage.single_return.return_name:'');
      this.mailReturnQueue=this.fun.setMailLanguage("消费队列",this.mailLanguage.single_return?this.mailLanguage.single_return.return_queue:'');
      this.mailReturnLog=this.fun.setMailLanguage("消费记录",this.mailLanguage.single_return?this.mailLanguage.single_return.return_log:'');
    },


    //初始化参数
    initData() {
      this.httpUrl = "plugin.single-return.api.single-return.get-single-return-queue";
      currentTabIndex = "0";
      is_first_content = false;
      is_second_content = false;
      this.task = false;

      this.activeName = 'first';

      this.first_content = [];
      this.second_content = [];

      this.alreadyReturn = 0.00;
      this.each_return_rate = 0;
      this.order_return_rate = 0;
      this.returnAmountTotal = 0.00;
      this.notReturn = 0.00;

    },

    //初始化数据
    getData() {
      let that = this;
      $http.get('plugin.single-return.api.single-return.get-single-return-statistic', {}, '').then(function (response) {
        if (response.result == 1) {
          that.alreadyReturn = response.data.alreadyReturn;
          that.each_return_rate = response.data.each_return_rate;
          that.order_return_rate = response.data.order_return_rate;
          that.returnAmountTotal = response.data.returnAmountTotal;
          that.notReturn = response.data.notReturn;
          that.task = response.data.task;
          that.valid = response.data.valid;
          that.totay = response.data.totay;
          that.single_return_show = response.data.single_return_show;
        } else {
          that.$toast(response.msg);
        }
      }, function (response) {
        that.$toast(response.msg);
      });
    },


    //返现队列详情
    toReturnInfo(id){
      this.$router.push(this.fun.getUrl('single_return_list_info', {"id":id}));
    },

    getReturnList() {
      let that = this;
      $http.get('plugin.single-return.api.single-return.get-single-return-queue', {}, '').then(function (response) {
        if (response.result == 1) {
          that.first_content=response.data;
        } else {
          this.$toast(response.msg);
        }
      }, function (response) {
        this.$toast(response.msg);
      });
    },


    //获取返现
    getReturnListInfo()
    {
      let that = this;
      $http.get('plugin.single-return.api.single-return.get-single-return-log', {}, '').then(function (response) {
        if (response.result == 1) {
          that.second_content=response.data;
        } else {
          this.$toast(response.msg);
        }
      }, function (response) {
        this.$toast(response.msg);
      });
    },

    //设置选择后的数据
    setDataByTabIndex() {
      if (currentTabIndex == "0" && !is_first_content) {
        is_first_content = true;
        this.getReturnList();//获取返现队列
      } else if (currentTabIndex == "1" && !is_second_content) {
        is_second_content = true;
        this.getReturnListInfo();//获取返现详情
      }
    },
    getJson(){
      if(this.activeName == "first"){
        return {};
      }else{
        return{
          award_status:this.activeName1
        };
      }
    },
    getListData(){
      this.loading = true;
      $http.post(this.httpUrl,{page:1,...this.getJson()}).then(({result,data,msg})=>{
        this.loading = false;
        if(result == 1){
          this.listData = data.data;
          this.setnoMore(this.logPage == data.last_page);
        } else this.$toast(msg);
      });
    },
    setnoMore(bool){
      this.noMore = bool;
      this.isLoadMore = !bool;
    },
    getMoreData(){
      this.loading = true;
      let page = this.logPage + 1;
      this.isLoadMore = false;
      $http.post(this.httpUrl,{page,...this.getJson()}).then(({result,data,msg})=>{
        this.loading = false;
        if(result == 1){
          this.listData.push(...data.data);
          this.setnoMore(this.logPage == data.last_page);
          this.logPage = page;
        }else this.$toast(msg);
      });
    },
    //tab 点击
    handleClick1(name){
      if(activeName1 == name) return false;
      activeName1 = name;
      this.logPage = 1;
      this.listData = [];
      this.getListData();
    },
    handleClick(name) {
      if(activeName == name) return false;
      activeName = name;
      this.logPage = 1;
      this.listData = [];
      if(name == "first"){
        this.httpUrl = "plugin.single-return.api.single-return.get-single-return-queue";
      }else{
        this.httpUrl = "plugin.single-return.api.single-return.get-single-return-log";
      }
      this.getListData();
      return false;
      //点击同tab 不刷新界面
      // if (currentTabIndex == tab.index) {
      //     return;
      // } else {
      //     currentTabIndex = tab.index;
      // }
      //因为修改组建改方法
      if (currentTabIndex == tab) {
        return;
      } else {
        currentTabIndex = tab;
      }
      this.setDataByTabIndex();
    },
  },
  components: { "yz-blank":()=>import("@/components/ui_components/yz_blank.vue") }
};